Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
lines-and-columns
Advanced tools
The lines-and-columns npm package is used to map between lines and columns to character offsets within a string, which is particularly useful when dealing with source code or any structured text format where line and column positions are commonly used.
Index to Position
This feature allows you to convert a line and column position into a character offset index. It is useful when you have a line and column number and you want to find the corresponding position in a flat string.
{"const LinesAndColumns = require('lines-and-columns');\nconst lines = new LinesAndColumns('Hello\nWorld');\nconst location = lines.indexForLocation({ line: 1, column: 2 }); // returns 9"}
Position to Index
This feature allows you to convert a character offset index back into a line and column position. It is useful when you have an index in a string and you need to find out which line and column it corresponds to.
{"const LinesAndColumns = require('lines-and-columns');\nconst lines = new LinesAndColumns('Hello\nWorld');\nconst position = lines.locationForIndex(7); // returns { line: 1, column: 0 }"}
The columnify package creates text-based columns suitable for console output, similar to how tables might be formatted in printed material. It differs from lines-and-columns in that it focuses on aligning columns of text rather than mapping positions within a text.
The line-column package provides similar functionality to lines-and-columns, allowing you to find the line and column position from a character offset and vice versa. It serves a similar purpose but may have different API details or performance characteristics.
The line-numbers package is used to prepend line numbers to a block of text. While it deals with lines in text, it does not provide the bidirectional mapping between line/column and character offset that lines-and-columns offers.
Maps lines and columns to character offsets and back. This is useful for parsers and other text processors that deal in character ranges but process text with meaningful lines and columns.
$ npm install [--save] lines-and-columns
import { LinesAndColumns } from 'lines-and-columns'
const lines = new LinesAndColumns(
`table {
border: 0
}`
)
lines.locationForIndex(9)
// { line: 1, column: 1 }
lines.indexForLocation({ line: 1, column: 2 })
// 10
MIT
FAQs
Maps lines and columns to character offsets and back.
The npm package lines-and-columns receives a total of 40,449,232 weekly downloads. As such, lines-and-columns popularity was classified as popular.
We found that lines-and-columns demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.